package com.yjn.student.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class ResultVo<T> {
    private String code;
    private String msg;
    private T data;

    public ResultVo(T data){
        this.data = data;
    }

    //执行成功，但没有数据，使用增删改查操作
    public static ResultVo success(){
        ResultVo resultVo = new ResultVo();
        resultVo.setCode("0");
        resultVo.setMsg("成功");
        return resultVo;
    }

    //执行成功并返回的数据
    public static <T> ResultVo<T> success(T data){
        ResultVo<T> resultVo = new ResultVo<>(data);
        resultVo.setCode("0");
        resultVo.setMsg("成功");
        return resultVo;
    }

    //执行失败，msg可以封装失败信息
    public static ResultVo error(String msg){
        ResultVo resultVo = new ResultVo();
        resultVo.setCode("-1");
        resultVo.setMsg(msg);
        return resultVo;
    }
}
